`!Buffer`! is an API that provides file-like read/write operations over a `F0af`_`[channel`:/page/wiki.mu`path=Channel]`_`f, enabling stream-like bidirectional transfer of binary data with automatic BZ2 compression.
>>Usage
With `F0af`_`[RNS`:/page/wiki.mu`path=RNS]`_`f:
`B100`F9d9# Create a buffer over a link's channel`f`b
`B100`F9d9channel = link.get_channel()`f`b
`B100`F9d9buffer = RNS.Buffer.create_bidirectional_buffer(0, 0, channel, ready_callback)`f`b
`B100`F9d9`f`b
`B100`F9d9# Write data`f`b
`B100`F9d9buffer.write("hello, world".encode("utf-8"))`f`b
`B100`F9d9buffer.flush()`f`b
`B100`F9d9`f`b
`B100`F9d9# Read data in callback`f`b
`B100`F9d9def ready_callback(ready_bytes: int):`f`b
`B100`F9d9 data = buffer.read(ready_bytes)`f`b
For a more comprehensive use case, see the Buffer example in the manual.
>>Reticulum concepts
`F0af`_`[Announce`:/page/wiki.mu`path=Announce]`_`f • `F0af`_`[Blackhole`:/page/wiki.mu`path=Blackhole]`_`f • Buffer • `F0af`_`[Channel`:/page/wiki.mu`path=Channel]`_`f • `F0af`_`[Destination`:/page/wiki.mu`path=Destination]`_`f • `F0af`_`[Discovery`:/page/wiki.mu`path=Discovery]`_`f • `F0af`_`[Identity`:/page/wiki.mu`path=Identity]`_`f • `F0af`_`[Instance`:/page/wiki.mu`path=Instance]`_`f • `F0af`_`[Interface`:/page/wiki.mu`path=Interface]`_`f • `F0af`_`[Interface Access Code`:/page/wiki.mu`path=Interface_Access_Code]`_`f (IFAC) • `F0af`_`[Link`:/page/wiki.mu`path=Link]`_`f • `F0af`_`[Network identity`:/page/wiki.mu`path=Network_identity]`_`f • `F0af`_`[Node`:/page/wiki.mu`path=Node]`_`f • `F0af`_`[Packet`:/page/wiki.mu`path=Packet]`_`f • `F0af`_`[Path`:/page/wiki.mu`path=Path]`_`f • `F0af`_`[Propagation node`:/page/wiki.mu`path=Propagation_node]`_`f • `F0af`_`[Resource`:/page/wiki.mu`path=Resource]`_`f • `F0af`_`[Stamp`:/page/wiki.mu`path=Stamp]`_`f • `F0af`_`[Transport node`:/page/wiki.mu`path=Transport_node]`_`f
>>Buffer
`!Source:`! `F0af`_`[Buffer.py ↗`a8d24177d946de4f1f0a0fe1af9a1338:/page/blob.mu`g=reticulum|r=reticulum|ref=HEAD|path=RNS/Buffer.py]`_`f
`!API:`! `F0af`_`[RNS.Buffer ↗`a8d24177d946de4f1f0a0fe1af9a1338:/page/blob.mu`g=reticulum|r=reticulum|ref=HEAD|path=docs/markdown/reference.md|anchor=RNS.Buffer]`_`f